package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class ReservationLibrary here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class ReservationLibrary
{
    private ArrayList<Reservation> reservations;

    private static ReservationLibrary instance;

    private ReservationLibrary()
    {
        reservations = new ArrayList<Reservation>();
    }

    public static ReservationLibrary getReservationLib()
    {
        if(instance == null)
        {
            instance = new ReservationLibrary();
        }
        
        return instance;
    }
    
    public void addReservation(Reservation _resv)
    {
        reservations.add(_resv);
    }
    
    public ArrayList<Reservation> getAllReservations()
    {
        return reservations;
    }
    
    public Reservation getReservationById(int _id)
    {
        Reservation _resv = null;
        int index = 0;
        boolean found = false;
        
        while(!found && index < reservations.size())
        {
            Reservation _searchResv = reservations.get(index);
            
            if(_searchResv.getReservationId() == _id)
            {
                _resv = _searchResv;
                found = true;
            }
            else
            {
                index++;
            }
        }
        
        return _resv;
    }
    
    public void removeReservation(Reservation _resv)
    {
        reservations.remove(_resv);
    }
}
